package tech.aistar.corejava.day10.homework;

import tech.aistar.corejava.util.DateUtil;

import java.util.Calendar;
import java.util.Scanner;

/**
 * @author success
 * @version 1.0
 * @description:本类用来演示:
 * @date 2019/7/25 0025
 */
public class PrintCalendarDemo {
    public static void main(String[] args) {
        //1.创建Scanner对象
        Scanner sc = new Scanner(System.in);
        System.out.print("请您输入年份:>");
        int year = sc.nextInt();

        System.out.print("请您输入月份:>");
        int month = sc.nextInt();

        printCalendar(year,month);
    }

    /**
     * 思路:
     *  1 - 求出某年某月最大天数
     *
     * 根据年月来输出日历
     * @param year
     * @param month
     */
    private static void printCalendar(int year, int month) {
        //1. 获取某年某月的最大天数
        int maxDays = DateUtil.getMaxDays(year,month);

        //2. 获取某年某月的1号是周几
        int week = DateUtil.getDayOfWeeks(year,month,1);

        //3. 获取今天是几号
        int date = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);

        System.out.println("\t\t"+year+"年"+month+"月");
        System.out.println("日\t一\t二\t三\t四\t五\t六");

        //定义一个计数器,用来控制换行
        int count = 0;

        //4. 任务打印1号是周几的之前的所有的空格
        //目的是把1号挤到对应的周几的位置
        for (int i = 0; i < week; i++) {
            System.out.print("\t");
            count++;
        }

        //5. 打印1 - 最大天数
        for (int i = 1; i <= maxDays ; i++) {
            if(i == date){
                System.out.print(i+"*\t");
            }else{
                System.out.print(i+"\t");
            }
            count++;

            //换行
            if(count == 7){
                System.out.println();
                count = 0;
            }
        }
    }
}
